package com.atguigu.spring5.service;

import com.atguigu.spring5.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

// @Component @Controller @Service @Repository 四个注解功能一样
// @Component(value = "userService")
@Service
public class UserService {

    // 普通类型注入
    @Value(value = "abc")
    private String name;

    // 添加注入属性注解，不需要set方法
//    @Autowired  // 根据类型注入
//    @Qualifier(value = "userDaoImpl1")  // 根据名称注入
//    private UserDao userDao;

    // @Resource   // 默认根据类型注入
    @Resource(name = "userDaoImpl1")    // 根据名称注入
    private UserDao userDao;

    public void add() {
        System.out.println("service add......" + name);
        userDao.add();
    }
}
